package com.barbeque.mall.controller;


import com.barbeque.mall.bean.BasePageInfo;
import com.barbeque.mall.bean.BaseRespVo;
import com.barbeque.mall.bean.param.CommonData;
import com.barbeque.mall.bean.param.User;
import com.barbeque.mall.bean.user.MarketUser;
import com.barbeque.mall.service.UserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


@RestController
@RequestMapping("admin/user")
public class AdminUserController {
    @Autowired
    UserService userService;

    /*@RequestMapping("list")
    public BaseRespVo list(Integer page,Integer limit, String sort,String order) {

    }*/

    //将Handler方法和权限建立耦合关系，访问这个Handler方法需要注解中的权限
    @RequiresPermissions("admin:user:list")
    @RequestMapping("list")
    //public BaseRespVo list(String username, Integer page, Integer limit, String sort, String order) {
    public BaseRespVo list(String username, String mobile, BasePageInfo info) {
        CommonData<MarketUser> data = userService.selectUsers(username, mobile, info);
        BaseRespVo baseRespVo = BaseRespVo.ok(data);
        baseRespVo.setErrmsg("成功");
        return baseRespVo;
    }

    /**
     * http://182.92.235.201:8083/admin/user/update
     * 会员修改
     */
    @RequiresPermissions("admin:update:list")
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MarketUser marketUser) {

        userService.updateUser(marketUser);
        return BaseRespVo.ok(1);
    }

    /**
     * http://182.92.235.201:8083/admin/user/detail?id=2
     * 根据id查询
     */
    @RequiresPermissions("admin:detail:list")
    @RequestMapping("detail")
    public BaseRespVo selectById(@RequestParam("id")Integer id) {

        MarketUser marketUser = userService.selectUserById(id);

        return BaseRespVo.ok(marketUser);
    }

}
